package com.hangim.pce.enums;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.google.common.collect.Lists;

import java.util.List;

/**
 * 药品类型
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum DrugType {
    WEST_MEDICINE("WEST_MEDICINE", 1, "西药"),
    HERBAL("MEDICINE", 2, "中草药"),
    CHINESE_PATENT_DRUG("CHINESE_PATENT_DRUG", 3, "中成药"),
    VACCINE("VACCINE", 4, "疫苗"),
    MATERIAL("MATERIAL", 5, "材料"),
    OTHER("OTHER", 0, "其他");

    // 类型
    private final String code;
    // 描述
    private final String desc;
    // 编号
    private final Integer num;

    DrugType(final String code, final Integer num, final String desc) {
        this.code = code;
        this.desc = desc;
        this.num = num;
    }

    public static DrugType getDrugType(String code) {
        DrugType[] ts = DrugType.values();
        for (DrugType t : ts) {
            if (t.getCode().equalsIgnoreCase(code)) {
                return t;
            }
        }
        return OTHER;
    }

    /**
     * 把所有枚举定义转换成实体
     *
     * @return List<DrugType>
     */
    public static List<DrugType> getList() {
        List<DrugType> list = Lists.newArrayList();

        DrugType[] ts = DrugType.values();
        for (DrugType type : ts) {
            list.add(type);
        }
        return list;
    }

    public static DrugType getDrugTypeyDesc(String desc) {
        DrugType[] ts = DrugType.values();
        for (DrugType t : ts) {
            if (t.getDesc().contains(desc)) {
                return t;
            }
        }
        return OTHER;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public Integer getNum() {
        return num;
    }
}
